package org.shezhua.android.i18n.model;

import java.util.HashMap;


public class ResValues extends HashMap<String, ResString> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4213404986944620512L;
	private String key;
	
	public ResValues(String key) {
		super();
		this.key = key;
	}
	
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}

	public Object getString(String language) {
		ResString rs = get(language);
		if(rs != null) {
			return rs.getValue();
		}
		return "";
	}
	
	public ResString setString(String language, Object value) {
		ResString rs = get(language);
		String val = value != null? value.toString() : null;
		if(rs != null) {
			rs.setUpdate(val);
		} else {
			rs = new ResString();
			rs.setKey(this.key);
			rs.setUpdate(val);
			rs.setFileName(language);
			rs.setModified(true);
			put(language, rs);
		}
		return rs;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		ResValues other = (ResValues) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		return true;
	}
}
